package com.zl.cms.dto;

import com.zl.cms.model.Channel;
import com.zl.cms.model.Topic;
import com.zl.cms.model.User;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Min;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;

/**
 * User: zl email:c3tc3tc3t@126.com Date: 14-3-19 Time: 上午9:29
 */
public class TopicDto {
  private int id;
  /**
   * 文章标题
   */
  private String title;
  /**
   * 
   * 文章关键字,通过 | 分割不同的关键字
   */
  private String keyword;

  /**
   * 栏目图片id,如果该栏目是图片类型的栏目,就会显示这个id的图片
   */
  private int channelPicId;

  /**
   * 文章状态,默认为0未发布，1表示已经发布
   */
  private int status;
  /**
   * 是否是推荐的文章
   */
  private int recommend;
  /**
   * 文章内容
   */
  private String content;
  /**
   * 文章摘要
   */
  private String summary;
  /**
   * 文章发布时间
   */
  private String publishDate;
  /**
   * 文章栏目id
   */
  private String cid;

  private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  @NotEmpty(message = "文章标题不能为空")
  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getKeyword() {
    return keyword;
  }

  public void setKeyword(String keyword) {
    this.keyword = keyword;
  }

  public int getChannelPicId() {
    return channelPicId;
  }

  public void setChannelPicId(int channelPicId) {
    this.channelPicId = channelPicId;
  }

  public int getStatus() {
    return status;
  }

  public void setStatus(int status) {
    this.status = status;
  }

  public int getRecommend() {
    return recommend;
  }

  public void setRecommend(int recommend) {
    this.recommend = recommend;
  }

  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }

  public String getSummary() {
    return summary;
  }

  public void setSummary(String summary) {
    this.summary = summary;
  }

  public String getPublishDate() {
    return publishDate;
  }

  public void setPublishDate(String publishDate) {
    this.publishDate = publishDate;
  }

  public String getCid() {
    return cid;
  }

  public void setCid(String cid) {
    this.cid = cid;
  }

  public TopicDto() {}

  public TopicDto(Topic topic) {
    this.setChannelPicId(topic.getChannelPicId());
    this.setContent(topic.getContent());
    this.setId(topic.getId());
    this.setKeyword(topic.getKeyword());
    this.setPublishDate(sdf.format(topic.getPublishDate()));
    this.setRecommend(topic.getRecommend());
    this.setStatus(topic.getStatus());
    this.setSummary(this.getSummary());
    this.setTitle(topic.getTitle());
  }

  public TopicDto(Topic topic, String cid) {
    this.setChannelPicId(topic.getChannelPicId());
    this.setContent(topic.getContent());
    this.setId(topic.getId());
    this.setCid(cid);
    this.setKeyword(topic.getKeyword());
    this.setPublishDate(sdf.format(topic.getPublishDate()));
    this.setRecommend(topic.getRecommend());
    this.setStatus(topic.getStatus());
    this.setSummary(this.getSummary());
    this.setTitle(topic.getTitle());
  }

  public Topic getTopic() {
    Topic t = new Topic();
    t.setChannelPicId(this.getChannelPicId());
    t.setContent(this.getContent());
    t.setKeyword(this.getKeyword());
    t.setId(this.getId());
    try {
      t.setPublishDate(sdf.parse(this.getPublishDate()));
    } catch (ParseException e) {
      t.setPublishDate(new Date());
    }
    t.setRecommend(this.getRecommend());
    t.setStatus(this.getStatus());
    t.setSummary(this.getSummary());
    t.setTitle(this.getTitle());
    return t;
  }

}
